::install_github("wilkelab/cowplot")
remotesinstall.packages("colorspace", repos = "http://R-Forge.R-project.org")
::install_github("clauswilke/colorblindr") remotes
0. Basic Information
To use colorblind-friendly palettes in R, you mainly need the following packages. Be sure that we checked the plots with these packages before saving the plots. Thank you!
1. colorbindr
Simulate colorblindness in production-ready R figures. Written by Claire D. McWhite and Claus O. Wilke.
Official repo: https://github.com/clauswilke/colorblindr
1.1 Installation
It could also be installed with: (but you need to install pakfirst.
::pkg_install("clauswilke/colorblindr") pak
1.2 Demo
It is easy to follow the official document, first make a ggplot object like:
library(ggplot2)
<- ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.7)
fig fig
Then we could use this package to check in different simulations:
library(colorblindr)
Loading required package: colorspace
cvd_grid(fig)
It is also possible to inspect it in the interactive app, I just show the script, it will not open a tab for readers.
view_cvd(fig) # starts the interactive app
2. colorblindcheck
Check Color Palettes for Problems with Color Vision Deficiency
Official repo: https://github.com/Nowosad/colorblindcheck
2.1 Installation
install.packages("colorblindcheck")
2.2 Demo
library(colorblindcheck)
Attaching package: 'colorblindcheck'
The following object is masked from 'package:colorblindr':
palette_plot
= rainbow(n = 7)
rainbow_pal rainbow_pal
[1] "#FF0000" "#FFDB00" "#49FF00" "#00FF92" "#0092FF" "#4900FF" "#FF00DB"
#> [1] "#FF0000" "#FFDB00" "#49FF00" "#00FF92" "#0092FF" "#4900FF" "#FF00DB"
palette_check(rainbow_pal, plot = TRUE)
name n tolerance ncp ndcp min_dist mean_dist max_dist
1 normal 7 12.13226 21 21 12.132257 61.06471 107.63470
2 deuteranopia 7 12.13226 21 19 2.572062 44.29065 85.87461
3 protanopia 7 12.13226 21 17 3.647681 47.63882 83.28286
4 tritanopia 7 12.13226 21 20 2.025647 47.41585 83.77189